package com.bnd.controller;

import com.bnd.common.BaseResponse;
import com.bnd.common.ResultUtils;
import com.bnd.domain.ChatHistory;
import com.bnd.domain.vo.ChatHistoryVO;
import com.bnd.service.ChatHistoryService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 聊天历史控制器
 */
@Slf4j
@RestController
@RequestMapping("/chatHistory")
public class ChatHistoryController {

    @Resource
    private ChatHistoryService chatHistoryService;

    /**
     * 根据角色ID获取聊天记录
     * @param characterId 角色ID
     * @return 聊天记录列表
     */
    @GetMapping("/byCharacter/{characterId}")
    public BaseResponse<List<ChatHistory>> getChatHistoryByCharacterId(@PathVariable Long characterId) {
        return ResultUtils.success(chatHistoryService.listByCharacterId(characterId));
    }

    /**
     * 删除角色的聊天历史记录
     * @param characterId 角色ID
     * @return 删除结果
     */
    @DeleteMapping("/del/{characterId}")
    public BaseResponse<String> deleteChatHistory(@PathVariable Long characterId) {
        chatHistoryService.removeByCharacterId(characterId);
        return ResultUtils.success("删除成功！");
    }

    /**
     * 获取每个角色的第一条聊天记录
     * @param keyword 搜索关键词
     * @return 第一条聊天记录列表
     */
    @GetMapping("/firstList")
    public BaseResponse<List<ChatHistoryVO>> selectFirstChatByCharacter(@RequestParam(value = "keyword", required = false, defaultValue = "全部") String keyword){
        return ResultUtils.success(chatHistoryService.selectFirstChatByCharacter(keyword));
    }
}
